package com.study.samsung.Dao;

import com.study.samsung.Entity.Succession;
import com.study.samsung.Utils.RowMapper;
import com.study.samsung.Utils.SQLHelper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class SuccessionDao {
    SQLHelper helper = new SQLHelper();

    public List<Succession> selectAll(){
        String sql = "select * from succession";
        return helper.query(sql,new SuccessionRowMapper());
    }

    public Integer changename(Integer xid,String xname){
        String sql = "update succession set xname = ? where xid = ?";
        return helper.update(sql,xname,xid);
    }

    public Integer addcategory(String xname){
        String sql = "insert into succession values(?,?)";
        return helper.insert(sql,null,xname);
    }

    public Integer deladdcategory(Integer xid){
        String sql = "delete from succession where xid = ?";
        return helper.update(sql,xid);
    }


    class SuccessionRowMapper implements RowMapper<Succession>{

        @Override
        public Succession map(ResultSet rs) throws SQLException {
            return new Succession(rs.getInt("xid"),
                    rs.getString("xname"));
        }
    }
}
